package entity

import (
	"context"
	"fmt"

	proto3x "origin/model/proto3x"

	"google.golang.org/grpc"
)

type EntityServer struct {
	proto3x.UnimplementedAuthServiceServer
}

func (e EntityServer) Single(ctx context.Context, req *proto3x.LoginRequest) (*proto3x.LoginResponse, error) {
	fmt.Println("receive", req.String())
	return &proto3x.LoginResponse{
		AccessToken: "AccessToken",
		ExpiresIn:   1000,
	}, nil
}

// stream
func (e EntityServer) List(stream grpc.ClientStreamingServer[proto3x.LoginRequest, proto3x.LoginResponse]) error {
	fmt.Println("List")
	recv, err := stream.Recv()
	if err != nil {
		return err
	}
	fmt.Println("recv", recv.String())
	stream.SendAndClose(&proto3x.LoginResponse{
		AccessToken: "List",
		ExpiresIn:   2000,
	})
	return nil
}
func (e EntityServer) SingleResp(req *proto3x.LoginRequest, stream grpc.ServerStreamingServer[proto3x.LoginResponse]) error {
	fmt.Println("SingleResp")
	return stream.SendMsg("name")

}
func (e EntityServer) ListResp(stream grpc.BidiStreamingServer[proto3x.LoginRequest, proto3x.LoginResponse]) error {
	recv, err := stream.Recv()
	if err != nil {
		return err
	}
	fmt.Println("recv", recv.String())
	return stream.SendMsg("ListResp")

}
